export default {
	namespaced:true,
	state:()=>({
		// 读取本地持久化的address信息到vuex的state
		address:JSON.parse(uni.getStorageSync('address')||'{}'),
		token:uni.getStorageSync('token')||'',
		userinfo:JSON.parse(uni.getStorageSync('userinfo')||'{}'),
		// 重定向
		redirectInfo:null
	}),
	
	mutations:{
		updateAddress(state,address){
			state.address = address
			// 通过this.commit方法，调用m_user模块下的saveAddressToStorage方法将address持久化到本地
			this.commit('m_user/saveAddressToStorage')
		},
		// 将address持久化存储到本地的mutation方法
		saveAddressToStorage(state){
			uni.setStorageSync('address',JSON.stringify(state.address))
		},
		// 将userinfo持久化存储到本地的mutation方法
		saveUserInfoToStorage(state){
			uni.setStorageSync('userinfo',JSON.stringify(state.userinfo))
		},
		updateUserInfo(state,userinfo){
			state.userinfo = userinfo
			this.commit('m_user/saveUserInfoToStorage')
		},
		updateToken(state,token){
			state.token = token
			this.commit('m_user/saveTokenToStorage')
		},
		// 将token持久化存储到本地的mutation方法
		saveTokenToStorage(state){
			uni.setStorageSync('token',state.token)
		},
		updateRedirectInfo(state,info){
			state.redirectInfo = info
		}
	},
	getters:{
		addressStr(state){
			if(!state.address.provinceName) return ''
			return state.address.provinceName + state.address.cityName + state.address.countyName+state.address.detailInfo
		}
	}
}